//
//  RNGameSDK.cpp
//

#include "../RNGameSDK.h"


CRNGameSDK::~CRNGameSDK()
{
}

// StartApp
bool CRNGameSDK::StartApp(const char* packageName,const unsigned char* lpParam, int nSize)
{
    return true;
}

// judge packname Exist?
bool CRNGameSDK::IsExistApk(const char* packageName)
{
    return true;
}
// InstallApk
bool CRNGameSDK::InstallApk(const char* filePath)
{
    return true;
}
// getVersion
int CRNGameSDK::GetApkVersionCode(const char* packName)
{
    return 1;
}
// ªÒ»°∆Ù∂Ø≤Œ ˝–≈œ¢
bool CRNGameSDK::GetInfoParam(unsigned char *lpParam, int& nSize)
{
    return false;
}

// ªÒ»°µÁª∞∫≈¬Î
std::string CRNGameSDK::GetPhoneNumber()
{
    NSString *num = [[NSUserDefaults standardUserDefaults] stringForKey:@"SBFormattedPhoneNumber"];
    if (num==nil || [num length]==0)  {
        num=@"";
    }
    return [num UTF8String];
}
// øÕ∑˛
bool CRNGameSDK::CallPhone(const char *number)
{
    UIWindow* window = [[UIApplication sharedApplication] keyWindow];
    if (!window) return false;
    NSMutableString * str=[[NSMutableString alloc] initWithFormat:@"tel:%s",number];
    UIWebView * callWebview = [[UIWebView alloc] init];
    [callWebview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:str]]];
    [window addSubview:callWebview];
    [callWebview release];
    [str release];
    return true;
}

// ªÒ»°Õ¯¬Á◊¥Ã¨
int CRNGameSDK::GetNetWorkType()
{
    return 1;
}

bool CRNGameSDK::GamePay(std::uint32_t dwPayAmount, std::uint32_t wTotal, const std::string &orderID)
{
    //g_RNPayment.requestProducts(dwPayAmount, wTotal, orderID);
    return true;
}

bool CRNGameSDK::PaySuccess()
{
    return true;
}

void CRNGameSDK::UpdateApp(const char* url,const char* path)
{
    
    char szAppUrl[256]={0};
    sprintf(szAppUrl,"%s/iosdown.htm",url);
    //OpenUrl(szAppUrl);
    
    NSURL * urlStr = [NSURL URLWithString:[NSString stringWithUTF8String:szAppUrl]];
    if ([[UIApplication sharedApplication] canOpenURL:urlStr]) {
        NSLog(@"can go to open url");
        [[UIApplication sharedApplication] openURL:urlStr];
    }else{
        NSLog(@"can not go to open url");
    }
}

void CRNGameSDK::AiBeiPay(const char* account, const char* goodsname, int waresid, float totleprice)
{
//    cocos2d::Director::getInstance()->pause();
//    
//    AiPayModule *aiPay    =   [[AiPayModule alloc]init];
//    UIWindow *window = [[UIApplication sharedApplication] keyWindow];
//    
//   
//    
//    [window.rootViewController presentModalViewController:aiPay animated:YES];
//    
//    
//   [aiPay  account:account goodsname:goodsname waresid:waresid totleprice:totleprice];

    
//    AiPayModule *aiPay    =   [[AiPayModule alloc]init];
//    UIWindow    *window     =[[UIApplication sharedApplication].windows objectAtIndex:0];
//    [window setRootViewController:aiPay];
//    [aiPay  account:account goodsname:goodsname waresid:waresid totleprice:totleprice];
}

 void CRNGameSDK::PayResult()
{
    cocos2d::Director::getInstance()->resume();

}
void CRNGameSDK::OpenUrl(const char* url)
{
    NSURL * urlStr = [NSURL URLWithString:[NSString stringWithUTF8String:url]];//后面为参数
    if ([[UIApplication sharedApplication] canOpenURL:urlStr]) {
        NSLog(@"can go to open url");
        [[UIApplication sharedApplication] openURL:urlStr];
    }else{
        NSLog(@"can not go to open url");
    }
}